/**
 * 
 */
package com.designpattern.daoimpl;

import java.util.ArrayList;
import java.util.List;

import com.designpattern.dao.StudentDao;
import com.designpattern.vo.Student;

/**
 * Data Access Object concrete class:
 * This class implement methods in interface dao
 * This class is responsible to get data from a datasource
 * which can be a database...
 * @author Thong
 *
 */
public class StudentDaoImpl implements StudentDao {
	
	// list is working as a database.
	List<Student> students = null;
	
	public StudentDaoImpl() {
		students = new ArrayList<Student>();
		Student student1 = new Student(1, "Thong");
		Student student2 = new Student(2,"Ngoc");
		students.add(student1);
		students.add(student2);
	}
	
	@Override
	public List<Student> getAllStudents() {		
		return students;
	}

	@Override
	public void updateStudent(Student student) {
		students.get(student.getStudentCode()).setStudentName(student.getStudentName());
		System.out.println("Student have Student Code "+ student.getStudentCode() +
				" " + "updated in database");
		
	}

	@Override
	public void insertStudent(Student student) {
		students.add(student);
		System.out.println("inserted a new student who have Code:"
				+ student.getStudentCode() + "name: " + student.getStudentName()
				+ "into database");		
	}

	@Override
	public void deleteStudent(Student student) {
		students.remove(student);
		System.out.println("deleted  student who have Code:"
				+ student.getStudentCode() + "name: " + student.getStudentName()
				+ "from database");		
		
		
	}

}
